package com.example.a2205douyin;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.a2205douyin.adapter.GiftAdapter;
import com.example.a2205douyin.adapter.LiveAdapter;
import com.example.a2205douyin.baseMVVM.view.BaseActivity;
import com.example.a2205douyin.databinding.ActivityLive2Binding;
import com.example.a2205douyin.databinding.ActivityLiveBinding;
import com.example.a2205douyin.db.Account;
import com.example.a2205douyin.db.AppDBUtils;
import com.example.a2205douyin.entity.GiftEntity;
import com.example.a2205douyin.entity.ResultEntity;
import com.example.a2205douyin.entity.VideoEntity;
import com.example.a2205douyin.live.BaoCon;
import com.example.a2205douyin.live.GiftControl;
import com.example.a2205douyin.live.LiveViewModel;
import com.example.a2205douyin.pay.PayActivity;

import java.util.ArrayList;
import java.util.List;

public class Live2Activity extends BaseActivity<ActivityLive2Binding, LiveViewModel> {
    List<VideoEntity.DataBean> videos = new ArrayList<>();
    LiveAdapter liveAdapter;
    int index;

    @Override
    protected void initData() {

        viewModel.videoSuccess.observe(this, new Observer<VideoEntity>() {
            @Override
            public void onChanged(VideoEntity entity) {
                if(entity.getCode()==200){
                    videos.addAll(entity.getData());
                    liveAdapter.notifyDataSetChanged();
                    binding.rv.scrollToPosition(index);
                }
            }
        });

    }

    @Override
    protected void initView() {
         liveAdapter = new LiveAdapter(R.layout.item_live,videos);
         binding.rv.setAdapter(liveAdapter);
         binding.rv.setLayoutManager(new LinearLayoutManager(this));
         viewModel.video(1,30);
         index = (int) getIntent().getExtras().get("index");

         liveAdapter.addChildClickViewIds(R.id.iv_video_close);
         liveAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
             @Override
             public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                 switch (view.getId()){
                     case R.id.iv_video_close:
                         finish();
                         break;
                 }
             }
         });
    }





    @Override
    protected Class<LiveViewModel> getViewModel() {
        return LiveViewModel.class;
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_live2;
    }
}